<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/fn"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<%-- Displays a button. The following parameters can be used :
  - id : optional, the button ID.
--%>

<fieldset class="classic-small">

		<%-- The image  field --%>
		<jsp:include page="../../common/form/form-field-header.jsp">
		 <jsp:param name="code" value="${param.imgCode}"/>
		</jsp:include>

<c:choose>

	<c:when test="${not empty param.imgSrc}">

		<a href="#" class="bulle">
			<spring:theme code="field.product.modify.overview"/>
			<span><img src="${param.imgSrc}" alt="${param.imgAlt}" align="middle"></span>
		</a>

		<%-- Displaying the form field error message  --%>
		<jsp:include page="../../common/form/form-field-errors.jsp">
		  <jsp:param name="path" value="${param.imgPath}"/>
		</jsp:include>
		<jsp:include page="../../common/form/form-field-footer.jsp"/>

		<form:hidden path="${param.hiddenRealPath}"/>
		<form:hidden path="${param.hiddenPath}"/>

		<div id="hidden_${param.imgPath}"><form:hidden path="${param.imgPath}"/></div>

		<jsp:include page="/WEB-INF/jsp/common/form/form-field-header.jsp">
		 <jsp:param name="code" value="${param.imgCodeModify}"/>
		</jsp:include>
		<c:set var="hideShowNewImgScript" value="hideShow('${param.divId}', $('#hideShow${param.divId}Cbx').attr('checked'));" />
		<form:checkbox path="" onclick="${hideShowNewImgScript}" onkeyup="${hideShowNewImgScript}"
		 	onchange="${hideShowNewImgScript}" id="hideShow${param.divId}Cbx" value=""/>
		<jsp:include page="/WEB-INF/jsp/common/form/form-field-footer.jsp"/>

		<div id="${param.divId}" style="display:none">
			<%-- The new product image --%>
			<jsp:include page="/WEB-INF/jsp/common/form/form-field-text.jsp">
				<jsp:param name="code" value="${param.imgCodeNew}" />
				<jsp:param name="path" value="${param.imgPath}" />
				<jsp:param name="type" value="file"/>
			</jsp:include>

		</div>

	</c:when>

	<c:otherwise>

		<%-- The new product image --%>
		<jsp:include page="/WEB-INF/jsp/common/form/form-field-text.jsp">
			<jsp:param name="code" value="${param.imgCodeNew}" />
			<jsp:param name="path" value="${param.imgPath}" />
			<jsp:param name="type" value="file"/>
		</jsp:include>

	</c:otherwise>
</c:choose>

</fieldset>

<script type="text/javascript"><!--
  $(document).ready(function() {

	  // default value to be shown
	  showProductTypes($("#productType").val());

	  $('#${param.formId}').submit(function() {

		  var div = $("#${param.divId}");

		  // removing the input element
		  if(div.css('display') == 'none'){
			  div.remove();
		  }
		  else{
			  $("hidden_${param.imgPath}").remove();
		  }

		  return true;
		});
  });
</script>